<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>更新问题类型</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="/css/oksub.css">
	<script type="text/javascript" src="/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form ok-form" lay-filter="filter">
		<div class="layui-form-item">
			<label class="layui-form-label">编号ID</label>
			<div class="layui-input-block">
				<input type="text" name="dictId"  autocomplete="off" class="layui-input" readonly="readonly"
				       lay-verify="dictId">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">问题类型名称</label>
			<div class="layui-input-block">
				<input type="text" name="dictItemName"  autocomplete="off" class="layui-input"
				       lay-verify="dictItemName">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type="text" name="dictMemo" autocomplete="off" class="layui-input" lay-verify="dictMemo">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-block">
				<input type="checkbox" name="dictEnable" lay-skin="switch" lay-text="启用|停用"  ${dictEnable=='1'?'checked':''} >
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script>
	var initData;

	function initForm(data) {
		var jsonString = JSON.stringify(data);
		initData = JSON.parse(jsonString);
	}

	layui.use(["element", "form", "okLayer", "okUtils"], function () {
		var form = layui.form;
		var okLayer = layui.okLayer;
		var okUtils = layui.okUtils;
		okLoading.close();
		if(initData.dictEnable == "1"){
			initData.dictEnable = 1;
		}else{
			initData.dictEnable = 0;
		}
		form.val("filter", initData);


		

		form.on("submit(edit)", function (data) {
			console.info(data.field);
			if(data.field.dictEnable == "on"){
				data.field.dictEnable = "1";
			}else{
				data.field.dictEnable = "0";
			}
			okUtils.ajax("/api/problemType/edit", "post", data.field, true).done(function (response) {
				console.log(response);
				okLayer.greenTickMsg("编辑成功", function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
			}).fail(function (error) {
				console.log(error)
			});
			return false;
		});
	})
</script>
</body>
</html>
